home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / xecho11.zip / XECHO.ASM < prev    next >
Assembly Source File  |  1988-06-15  |  6KB  |  165 lines

  1.     PAGE ,132
  2. ; XECHO.ASM  version 1.1  -  by John Wright, 19-March-1988
  3. ;
  4. ; Utility for generating character strings which include control and special
  5. ; characters.  Strings are specified on the command line using "Lotus 1-2-3"
  6. ; like syntax with "\nnn" being translated as the ASCII code for decimal 'nnn'.
  7. ; Strings are sent to the standard output and may be redirected to a file or a
  8. ; device.  Note that unlike the ECHO command in DOS, XECHO does not append a
  9. ; CR,LF pair to the output string.
  10. ;
  11. ; Usage:
  12. ;         XECHO [xxxxx....] [> file or device spec]
  13. ;
  14. ;    where "x" can be either:
  15. ;    - any character which can be entered on a DOS command line (ie. blanks
  16. ;      and any keyboard characters or ALT-key sequences not filtered by DOS 
  17. ;      such as CR (Enter), LF, BS, DEL, ^C, ^P, ">", "<", "|", etc.);  all
  18. ;      characters are sent to standard output as is.
  19. ;       - a sequence of characters beginning with "\":
  20. ;      - "\" followed by 1 to 3 digits is translated as the ASCII code 
  21. ;        represented by interpreting the digits as a decimal value modulo
  22. ;        256; the sequence is terminated by a non-digit, the end of the
  23. ;        command line or a fourth digit.
  24. ;     - "\" followed by a non-digit character is translated as that char.
  25. ;
  26. ; Notes:
  27. ;    - TAB characters in the command line string are not expanded.
  28. ;       - leading blanks and TABs (between "xecho" and the first visible char.
  29. ;      following on the command line are skipped; to send strings beginning
  30. ;      with a blanks or tabs use \20 or \9 for at least for the first one.
  31. ;       - trailing blanks and TABs (between the last visible character of the
  32. ;      command and the CR, ">", "<", or "|") are preserved and sent as is.
  33. ;       - "\1", "\01" and "\001" are equivalent (assuming for the first two
  34. ;      cases that the following character is not a digit) to ^A; 
  35. ;       - "\0001" would be translated as ASCII NUL followed by "1".
  36. ;       - to send the back-slash character, "\", use "\\" in the command line.
  37. ;       - "\" at the end of the command line is ignored.
  38. ;       - the command "xecho >null" creates an empty file "null".
  39. ; XECHO is particularly useful for sending control strings to on-line devices
  40. ; such as printers or modems.  For instance "xecho \15>prn" selects condensed
  41. ; printing on an Epson compatible printer, "xecho \027@>prn" sends a printer
  42. ; reset, and "xecho \12>prn" sends a form-feed.
  43. ;
  44. ; Revisions:
  45. ;    1.0 -  2-March-88, J.W. - original
  46. ;    1.1 - 19-March-88, J.W. - limited no. digits after '\' to 3 for
  47. ;        compatibility with Lotus-style strings + improved code
  48. ;
  49. ; And lest we forget,
  50. ;    "Lotus" *and* "1-2-3" are trademarks of Lotus Development Corp.
  51. ;     "Epson" is a trademark of Seiko Epson Corp.
  52. ;
  53. ; XECHO is declared in the public domain by its author.
  54. ;
  55. ;
  56. escchar    equ '\'        ; escape char for special processing
  57. ;
  58. blank    equ 20h        ; blank char.
  59. tab    equ 09h        ; tab char.
  60. ;
  61. params  equ 80h        ; address of DOS command line buffer
  62. ;
  63. writefh    equ 40h        ; DOS function code to write to a file handle
  64. dosexit    equ 4ch        ; DOS function code to exit program
  65. ;
  66. stdout    equ 1        ; file handle for standard output
  67. ;
  68. ;
  69. doscall    MACRO function    ;; Call the DOS interrupt 
  70.     mov ah,function    ;; Put function number in AH 
  71.     int 21h
  72.     ENDM
  73. ;
  74. ;
  75.     org    0100h
  76. code    segment    public 'CODE'
  77.     assume    cs:code, ds:code, es:code, ss:code
  78. start    proc    far
  79.     mov si,params    ; SI = address of command line buffer
  80.     lodsb        ; load number of chars in param string.
  81.     mov cl,al    ; save it in CX register.
  82.     xor ch,ch    ; (zero high byte)
  83.     mov di,si    ; DI = SI (now params+1) so that the output string
  84.             ; overwrites the parameter string as it is processed.
  85. ;
  86. ;              loop for leading blanks and tabs
  87. ;
  88. loop1:    jcxz term    ; if no more chars, exit without doing anything
  89.     dec cx        ; else decrement CX
  90.     lodsb        ; and load next char.
  91.     cmp al,blank    ; if a blank, loop.
  92.     jz loop1
  93.     cmp al,tab    ; if a tab, loop.
  94.     jz loop1
  95.     jmp chkesc    ; else process it.
  96. ;
  97. ;              loop for characters to be processed
  98. ;
  99. loop2:    jcxz fin    ; if no more, goto output string
  100.     dec cx        ; else decrement CX
  101.     lodsb        ; and load next char.
  102. chkesc:    cmp al,escchar    ; if the escape char ('\')
  103.     jz escape    ; go to process it
  104. store:    stosb        ; else store as output char.
  105.     jmp loop2    ; continue.
  106. ;
  107. ;              process special escape sequences
  108. ;
  109. escape:    jcxz fin    ; if no more, ignore escape and go to output string
  110.     dec cx        ; else decrement CX
  111.     lodsb        ; and load next char.
  112.     cmp al,'0'    ; if less than "0", treat as regular char
  113.     jl store    ; (go store it).
  114.     cmp al,'9'    ; if greater than "9" treat as regular char
  115.     jg store    ; (go store it).
  116.     xor bx,bx    ; else zero BX to hold converted digit
  117.     mov bp,3    ; and set BP to 3, max no. of digits to convert
  118. ;
  119. ;              loop for digits in escape seq.
  120. ;
  121. loop3:    sub al,'0'    ; convert digit char to byte value in AX.
  122.     xor ah,ah    ; (zero high byte)
  123.     add bx,ax    ; BX = BX+AX
  124.     jcxz endesc    ; if no more char in line, finish escape processing
  125.     dec bp        ; else decrement BP
  126.     jz endesc    ; if zero, stop converting & finish escape processing
  127.     dec cx        ; else decrement CX
  128.     lodsb        ; and load next char.
  129.     cmp al,'0'    ; if less than "0", treat as reqular char and
  130.     jl backup    ; end of escape seq.
  131.     cmp al,'9'    ; if greater than "9", treat as regular char and
  132.     jg backup    ; end of escape seq.
  133.             ; else multiply BX by 10
  134.     mov dx,bx    ; (DX = BX)
  135.     shl dx,1    ; (DX = DX*2)
  136.     shl dx,1    ; (DX = DX*4)
  137.     add bx,dx    ; (BX = BX+DX)
  138.     shl bx,1    ; (BX = BX*2).
  139.     jmp loop3    ; goto add new digit into BX and continue
  140. ;
  141. ;              backup posn in command line buffer
  142. ;
  143. backup: inc cx        ; increment CX
  144.     dec si        ; decrement SI
  145. ;
  146. ;              end of escape seq processing
  147. ;
  148. endesc:    mov al,bl    ; AL = low byte of escape seq number in BX
  149.     jmp store    ; go to store it
  150. ;
  151. ;              output string
  152. ;
  153. fin:    mov dx,params+1    ; DX = address of start of output string.
  154.     mov cx,di    ; CX = DI = address of end of output string + 1.
  155.     sub cx,dx    ; CX = CX-DX = number of chars in output string.
  156.     jcxz term    ; if zero, end without doing anything
  157.     mov bx,stdout    ; else BX = file handle for standard output.
  158.     doscall writefh    ; write to file handle
  159. term:    xor al,al    ; zero al for exit code
  160.     doscall dosexit    ; exit program
  161. start    endp
  162.     code    ends
  163.     end
  164.